package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mall.annotation.OperationLog;
import com.mall.db.domain.Role;
import com.mall.db.service.RoleService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/system/role")
public class RoleController extends  BaseController<Role>{

    @Resource(name="roleService")
    private RoleService rs;

    @Override
    public Map<String, Object> find(Role role) {

        PageHelper.startPage(role.getPage(),role.getLimit());

        QueryWrapper<Role> qw = new QueryWrapper<>();
        List<Role> list = rs.list(qw);
        PageInfo<Role> page = new PageInfo<>(list,role.getLimit());

        return this.findMap(page.getList(),page.getTotal());
    }

    @Override
    @OperationLog(value = "角色新增",type = 0)
    public Map<String, Object> add(Role role) {
        boolean b = rs.save(role);
        return this.iud("新增",b,role);
    }

    @Override
    @OperationLog(value = "角色编辑",type = 0)
    public Map<String, Object> update(Role role) {
        boolean b = rs.updateById(role);
        return this.iud("编辑",b,role);
    }
}
